package com.zhangshitong.springbootModel.base;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.math.NumberUtils;



public abstract class BaseController {

	/**
	 * 成功响应
	 * @param data
	 * @return
	 */
	public ResMessage SuccessMessage(Object data){
		ResMessage d =new ResMessage(data);
		d.setStatus(StatuCode.SUCCESS);
		return d;
	}
	
	/**
	 * 失败响应
	 * @param data
	 * @return
	 */
	public ResMessage FaultMessage(Object data){
		ResMessage d =new ResMessage(data);
		d.setStatus(StatuCode.Fault);
		return d;
	}
	
	public Page getPageModel(HttpServletRequest request){
		try {
			String currentPage = request.getParameter("page");
			String pageSize = request.getParameter("pageSize");
			pageSize = null== pageSize?request.getParameter("limit"):pageSize;
			//验证
			if(!NumberUtils.isNumber(currentPage)){
				currentPage="1";
			}
			if(!NumberUtils.isNumber(pageSize)){
				pageSize="5";
			}
			Page pageModel = new Page();
			pageModel.setCurrentPage(Integer.parseInt(currentPage));
			pageModel.setPageSize(Integer.parseInt(pageSize));
			return pageModel;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
